import flatList from "./data/data1.js"

import { initBarOption, initPieOption } from "./utils/option.js"

let row = []
let id = 'name'
// 扁平化数组，表格
flatList.forEach(i => {
    row.push(i[id])
})


let barOption = initBarOption(flatList, {
    title: '柱状图',
    type: 'bar',
    row: 'name',
    column: ['salary', 'income', 'outcome'], // 表头
    legendMap: {
        salary: '工资',
        income: '收入',
        outcome: '支出',
    }
})

let lineOption = initBarOption(flatList, {
    title: '折线图',
    type: 'line',
    row: 'name',
    column: ['salary', 'income', 'outcome'],
    legendMap: {
        salary: '工资',
        income: '收入',
        outcome: '支出',
    }
})

let scattereOption = initBarOption(flatList, {
    title: '散点图',
    type: 'scatter',
    row: 'name',
    column: ['salary', 'income', 'outcome'],
    legendMap: {
        salary: '工资',
        income: '收入',
        outcome: '支出',
    }
})


let pieOption = initPieOption(flatList[0], {
    title: flatList[0].name,
    type: 'pie',
    map: {
        salary: '薪资',
        income: '收入',
        outcome: '支出',
    }
})



var barChart = echarts.init(document.getElementById('bar'));
var lineChart = echarts.init(document.getElementById('line'));
var scatterChart = echarts.init(document.getElementById('scatter'));
var pieChart = echarts.init(document.getElementById('pie'));


// 指定图表的配置项和数据

console.log('option', barOption, pieOption);
// 使用刚指定的配置项和数据显示图表。
barChart.setOption(barOption);
lineChart.setOption(lineOption)
scatterChart.setOption(scattereOption);
pieChart.setOption(pieOption)